import Vue from 'vue'
import App from './App.vue'
import axios from 'axios'

// 全局引用声明
import './assets/css/global.scss'
import DevicePixelRatio from '@/utils/devicePixelRatio'
new DevicePixelRatio().init()
Vue.prototype.$api = require('./api').default
Vue.prototype.$utils = require('./utils').default
Vue.prototype.$enum = require('./utils/enum').default
Vue.prototype.$pageMixin = require('./mixins/pageMixin').default
Vue.use(require('./components').default)
Vue.use(require('./mixins').default)
Vue.use(require('./directive').default)

Vue.config.productionTip = false

const startApp = async () => {
  axios.get(`${process.env.NODE_ENV !== 'development' ? '/' + require('../package.json').name : ''}/conf/config.json?time=${Date.now()}`).then(res => {
    document.getElementsByTagName('title')[0].innerText = res.data.title
    // 保存配置
    sessionStorage.setItem('TITLE', res.data.title)

    /** 默认环境 */
    if (process.env.NODE_ENV === 'development') {
      sessionStorage.setItem('APP_API1', res.data.app_api1)
      sessionStorage.setItem('APP_API2', res.data.app_api2)
    }
    /** 开发环境 */
    if (process.env.NODE_ENV === 'production') {
      sessionStorage.setItem('APP_API1', res.data.app_api1)
      sessionStorage.setItem('APP_API2', res.data.app_api2)
    }
    /** 测试环境 */
    if (process.env.NODE_ENV === 'test') {
      sessionStorage.setItem('APP_API1', res.data.app_test_api1)
      sessionStorage.setItem('APP_API2', res.data.app_test_api2)
    }
    new Vue({
      router: require('./router').default,
      store: require('./store').default,
      vuetify: require('./plugins/vuetify').default,
      elementUI: require('./plugins/elementUI').default,
      render: h => h(App)
    }).$mount('#app')
  })
}; startApp()
